export default {
    required(label: string) {
        return [
            { required: true, message: `${label}不能为空！` },
        ];
    },
    string(label: string) {
        return [{}];
    },
    password() {
        return [
            {
                validator: async (rule: any, value: any, callback: any) => {
                    let hasSix = /^\S{4,12}$/;
                    value && !hasSix.test(value) ?
                        callback("密码至少4到12位") :
                        callback();
                }
            }
        ];
    },
    equalPassword(label: string) {
        return [
            {
                validator: async (rule: any, value: any, callback: any) => {
                    const password = this.props.form.getFieldValue("password");

                    value && value !== password ?
                        callback("两次密码输入不一致！") :
                        callback();
                }
            }
        ];
    },
    validateFields(form: any) {
        return new Promise((resolve, reject) => {
            form.validateFields((errors: any, values: object) => {
                !errors ? resolve(values) : reject(errors);
            })
        });
    },
}
